package com.cyzy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Banner;
import com.cyzy.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("/page")
    public Result getBannerPage(
            @RequestParam(defaultValue = "1") Long currentPage,
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(required = false) String title,
            @RequestParam(required = false) Long bannerType,
            @RequestParam(required = false) Integer isVisible) {

        Banner banner = new Banner();
        banner.setCurrentPage(currentPage);
        banner.setPageSize(pageSize);
        banner.setTitle(title);
        banner.setBannerType(bannerType);
        banner.setIsVisible(isVisible);

        return bannerService.getBannerPage(banner);
    }

    @PostMapping("/add")
    public Result addBanner(@RequestBody Banner banner) {
        return bannerService.addBanner(banner);
    }

    @PostMapping("/update")
    public Result updateBanner(@RequestBody Banner banner) {
        return bannerService.updateBanner(banner);
    }

    @PostMapping("/delete/{bannerId}")
    public Result deleteBanner(@PathVariable Long bannerId) {
        return bannerService.deleteBanner(bannerId);
    }

    @PostMapping("/status/{bannerId}")
    public Result changeBannerStatus(
            @PathVariable Long bannerId,
            @RequestParam Integer isVisible) {
        return bannerService.changeBannerStatus(bannerId, isVisible);
    }
}